package com.dj.uphome.web.service.system.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dj.common.web.service.impl.BaseCrudServiceImpl;
import com.dj.uphome.web.mapper.system.SysRoleRightsMapper;
import com.dj.uphome.web.service.system.SysRoleRightsService;
import com.dj.uphome.web.vo.system.SysRoleRightsVo;

@Service
public class SysRoleRightsServiceImpl  extends BaseCrudServiceImpl<SysRoleRightsVo> implements SysRoleRightsService {
	@Autowired
	private SysRoleRightsMapper sysRoleRightsMapper;
	@Transactional
	public void create(int roleId, int[] menuIds) throws Exception {
		sysRoleRightsMapper.deleteByRoleId(roleId);
		if (null != menuIds && menuIds.length > 0) {
			List<SysRoleRightsVo> list = new ArrayList<SysRoleRightsVo>();
			for (int menuId : menuIds) {
				SysRoleRightsVo vo = new SysRoleRightsVo();
				vo.setRoleId(roleId);
				vo.setMenuId(menuId);
				list.add(vo);
			}
			sysRoleRightsMapper.save(list);
		}
	}

}
